import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { LoginModule } from './login/login.module';
import { CodeService } from './code/code.service';
import { CodeController } from './code/code.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthController } from './auth/auth.controller';
import { AuthService } from './auth/auth.service';
import { AuthModule } from './auth/auth.module';
import { JwtModule } from '@nestjs/jwt';
import { NoteModule } from './note/note.module';
import { databaseConfig } from './database.config';

@Module({
  imports: [
    UserModule,
    LoginModule,
    TypeOrmModule.forRoot({
      type: 'mysql',
      retryDelay: 500, //重试连接数据库间隔
      retryAttempts: 10, //重试连接数据库的次数
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: true,
      ...databaseConfig
    }),
    JwtModule.register({
      global: true,
      secret: 'testtoken',
      signOptions: { expiresIn: '1d' },
    }),
    AuthModule,
    NoteModule,
  ],
  controllers: [AppController, CodeController, AuthController],
  providers: [AppService, CodeService, AuthService],
})
export class AppModule {}
